<?php
/*
Enlightener V0.09 Codename Kerstpiek.
This software is copyrighted 2005, Michel Francois Bouwmans. All rights reserved.
*/

ob_start('ob_gzhandler');

$username="dragonballpalace2";
$password="";
$database="dragonballpalace2_nl_db";

$apik=$_POST['apikey'];
$uname=$_POST['user'];
$passwd=$_POST['pass'];
$client_version=$_POST['apiversion'];
$action=$_POST['mode'];
$xml_data=$_POST['XML']

header("Upgrade: HTTP/1.1, LIGHTAPI/0.1"); //Sends upgrade header for API-version checking by client.

require("apiauth.inc.php");

class xmlprocess{ //Processes XML for database usage.

function xmltobbcode($xml_data){ //Replace some XML tags to their BBcode substitutes.
$orgarray = array('<bold>', '</bold>', '<italics>', '</italics>', '<underline>', '</underline>', '</link>', '<link url=\"', '">');
$replarray = array('[B]', '[/B]', '[I]', '[/I]', '[U]', '[/U]', '[/url]', '[url=\"', '"]');

$xml_data = str_replace($orgarray, $replarray, $xml_data);

}

function xmlparse($xml_data){ //Parses XML.
$xml_parser_handle = xml_parser_create();

if(!xml_parse_into_struct($xml_parser_handle, $xml_data, $values, $index)){
header("HTTP/1.1 412 Precondition Failed");
sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($xml_parser_handle)), xml_get_current_line_number($xml_parser_handle));
die();
}
xml_parser_free($xml_parser_handle);

//Assign parsed XML to variables.
$post_id = $values[$index["IDENTIFIER"] [0]] ["value"];
$title = $values[$index["TITLE"] [0]] ["value"];
$author = $values[$index["AUTHOR"] [0]] ["value"];
$contributer = $values[$index["CONTRIBUTED"] [0]] ["value"];
$front_story = $values[$index["FRONT"] [0]] ["value"];
$ext_story = $values[$index["EXTENDED"] [0]] ["value"];
}
}

class xmlgenerate{

function bbcodetoxml($bbcod){
$orgarray = array('[B]', '[/B]', '[I]', '[/I]', '[U]', '[/U]', '[url]', '[/url]', '[url=]', '"]');
$replarray = arra('<bold>', '</bold>', '<italics>', '</italics>', '<underline>', '</underline>', '<link>', '</link>', '<link url=', '">');
$outputxml = str_replace($orgarray, $replarray, $xml_data);
}

function toxml ($input){
$output = "<posting>
    <title>$input['TITLE']</title>
    <identifier>$input['ID']</identifier>
    <author>$input['AUTHOR']</author>
    <contributer>$input['CONTRIBUTER']</contributer>
    <posted>$input['TIMEDATE']</posted>
    <front>
    $input['FRONT']
    </front>
    <extended>
    $input['EXT']
    </extended>
</posting>";
}
}

class database{

function connect(){
mysql_connect("localhost", $username, $password);
mysql_select_db($database);
}

function updatestory(){ //Update a story to a new version.
mysql_query("UPDATE enlight_postings SET title = '$title', author = '$author', contributer = '$contributer', front = '$front_story', ext = '$ext_story' WHERE id = '$post_id'");
}

function newstory(){ //Enter a new story into the database.
$date = date("Y-m-d H-s");

mysql_query("INSERT INTO enlight_postings VALUES ('', '$title', '$author', '$contributer', '$front_story', '$ext_story', '$date')");
}

function getstories(){ //Get stories from database.
$res = mysql_query("SELECT * FROM enlight_postings LIMIT 0, 5'");
$row = mysql_fetch_array($res);
$story1 = $row[0];
$story2 = $row[1];
$story3 = $row[2];
$story4 = $row[3];
$story5 = $row[4];
$story6 = $row[5];
mysql_free_result($res);
}

function disconnect(){
mysql_close();
}

}


?>
